package com.example.controller;

import com.example.annotation.AuthConfig;
import com.example.utils.R;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.ResponseEntity;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @Author 王鹤蒲
 * @Date 2023 07 31
 */

@RestController
@Api
@RequestMapping("/test")
public class TestController {

    @Autowired
    private RestTemplate restTemplate;

    @Autowired
    private PasswordEncoder bCryptPasswordEncoder;

    @Value("e748ad9053bf4a102a3c4cdc0639ea3f")
    private String key;

    @Value("110101")
    private String city;

    @GetMapping("/test1")
    @AuthConfig
    public R test1(){
      ResponseEntity responseEntity= restTemplate.getForEntity("https://restapi.amap.com/v3/weather/weatherInfo?city={1}&key={2}", Object.class,city,key);
     return R.success( responseEntity.getBody()) ;
    }

    @GetMapping("/test2")
    public void test2(){
        System.out.println(bCryptPasswordEncoder.encode("abc123"));
    }
}
